﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DCTAccess.Business;
using DCTLib.Common;
using DCTAccess.Business.Testing;
using DCTAccess.Business.Member;
using Obout.Grid;

public partial class AdminZone_TestingSystem : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }


    public void BindData()
    {
        //
        DataTable dtTesting = Testing.GetAllPointValue();
        Grid1.DataSource = dtTesting;
        Grid1.DataBind();
        //
        MemberFilter filter = new MemberFilter();
        DataTable dtMember = filter.GetMember();
        //Grid2.DataSource = dtMember;
        //Grid2.DataBind();
        //
        GridView1.DataSource = dtMember;
        GridView1.DataBind();
    }

    protected void UpdateRecord(object sender, GridRecordEventArgs e)
    {
        //Nothing
    }

    protected void btnBuy_Click(object sender, EventArgs e)
    {
        lblMsg.Text = "okie:";
        BindData();
    }

    private bool ValidateData()
    {
        bool validated = true;
        if (!ValidationHelper.IsNumber(txtPoint.Text))
        {
            lblError.Text = "Error! Giá trị nhập vào phải là số";
            return false;
        }
        else if (ValidationHelper.IsEmpty(txtPoint.Text))
        {
            lblError.Text = "Error! Trường dữ liệu trống";
            return false;
        }
        return validated;
    }

    protected void btnReset_Click(object sender, EventArgs e)
    {
        if (ValidateData())
        {
            int point = Convert.ToInt32(txtPoint.Text);
            if (Testing.ResetData(point))
            {
                lblLevelError.Text = "reset done.";
                Response.Redirect("TestingSystem.aspx");
                BindData();
            }
            else
            {
                lblLevelError.Text = "Cannot reset data";
            }
        }
        else
        {
            lblError.Text = "Error!";
        }
    }
}
